-
-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prototype: Macro expansion / lowering #329
Conversation
Begin working on macro expansion. So far this just expands backquotes. Also some changes to SyntaxNode make it possible to construct ASTs from these programmatically, without the source being available. And some basic support to allow us to track provenance through syntax transformations.
Allow `macroexpand` to call macros which only have an implementation in terms of the `Expr` data structure. Also add a `__macroname__` argument to pass the expression of the macro name as it appeared at macro invocation. Implement `@__FILE__` `@__LINE__` and `@__COLUMN__` in terms of this.
Macros expansion of macros which emit macros as part of their AST needs care when that AST contains interpolations: We don't want the second macro expansion to see the hygenic_scope expression. One way to do this is to transform hygenic_scope back into `SyntaxLiteral` on the fly. Also fix auto-escaping for expressions arising from the original scope by adding the necessary number of Expr(:esc)
Codecov Report
@@ Coverage Diff @@
## main #329 +/- ##
==========================================
- Coverage 96.54% 92.88% -3.67%
==========================================
Files 14 17 +3
Lines 4140 4608 +468
==========================================
+ Hits 3997 4280 +283
- Misses 143 328 +185
|
One of the many internal Base things we're using is likely different on <= 1.8
Plus subtle fixes to macro expansion prototype
@maleadt I've implemented a prototype of
Quick benchmarks suggest ~7x speed improvement over Base's current macro expansion compared with the
It's hard to get a perfectly fair comparison here but these kind of speedups are generally what I've observed in JuliaSyntax's parser vs the flisp as well. |
It looks like that benchmark above is measuring hygenic-scope resolution rather than macro expansion and this is the real cost. Hacking libjulia to add a function which doesn't call
This also means it's very hard to do a fair benchmark of this in the new prototype without also reimplementing the parts of lowering which do scope resolution. (Which I want to do! It's just a fair bit of work.) |
I see; thanks for clarifying! I had trouble myself too figuring out where the real cost of the |
This work is continuing over at https://github.com/c42f/JuliaLowering.jl so I'll close this. Over there I've got enough things working that we can produce a
At some point I'll port the |
This is the start of trying out some ideas from #327
Here I'm prototyping
JuliaSyntax.eval2()
andJuliaSyntax.include2()
which are some baby steps toward a "new frontend".Currently this code achieves the following
eval2()
are just normal Julia modules which can interoperate with code from old modules.MacroExpansionError
Fixing these issues with the frontend implies changing the representation of expression literals. Here I have a
SyntaxLiteral
type rather thanExpr
.All these things appear to work in this proof of concept so far. Things I'd like to play with...
CodeInfo
out directly without calling into the old frontend.SyntaxLiteral